package cn.hg.jbsa.common.dto;

import java.io.Serializable;

import cn.hg.jboot.core.constant.BaseConstants;

/**
 *
 * @author golly
 * @date 2021/10/22
 */
public class JbsaResponseDto<T> implements Serializable, BaseResponseDto<T> {

    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = 3868689456739381429L;

    public static <T> BaseResponseDto<T> fail() {
        return JbsaResponseDto.fail(null);
    }

    public static <T> BaseResponseDto<T> fail(int code, String msg) {
        return JbsaResponseDto.fail(code, msg, null);
    }

    public static <T> BaseResponseDto<T> fail(int code, String msg, T data) {
        return new JbsaResponseDto<T>(code, msg, false, data) {
            /**
             * serialVersionUID
             */
            private static final long serialVersionUID = 2403689168639520120L;
        };
    }

    public static <T> BaseResponseDto<T> fail(T data) {
        return JbsaResponseDto.fail(BaseConstants.RETURN_CODE_VALUE_FAILED, BaseConstants.RETURN_MESSAGE_VALUE_FAILED, data);
    }

    public static <T> BaseResponseDto<?> ok() {
        return JbsaResponseDto.ok(null);
    }

    public static <T> BaseResponseDto<T> ok(T data) {
        return new JbsaResponseDto<T>(BaseConstants.RETURN_CODE_VALUE_SUCCESSED, BaseConstants.RETURN_MESSAGE_VALUE_SUCCESSED,
            true, data) {
            /**
             * serialVersionUID
             */
            private static final long serialVersionUID = 2403689168639520120L;
        };
    }

    /**
     *
     */
    private int code = BaseConstants.RETURN_CODE_VALUE_SUCCESSED;

    /**
     *
     */
    private String message = BaseConstants.RETURN_MESSAGE_VALUE_SUCCESSED;

    /**
     *
     */
    private boolean success = true;

    /**
     *
     */
    private T data;

    public JbsaResponseDto() {}

    public JbsaResponseDto(int code, String message, boolean success) {
        this(code, message, success, null);
    }

    public JbsaResponseDto(int code, String message, boolean success, T data) {
        this.code = code;
        this.message = message;
        this.success = success;
        this.data = data;
    }

    /* (non-Javadoc)
     * @see cn.hg.jbsa.admin.dto.BaseResponseDto#getCode()
     */
    @Override
    public int getCode() {
        return this.code;
    }

    /* (non-Javadoc)
     * @see cn.hg.jbsa.admin.dto.BaseResponseDto#getData()
     */
    @Override
    public T getData() {

        return this.data;
    }

    /* (non-Javadoc)
     * @see cn.hg.jbsa.admin.dto.BaseResponseDto#getMessage()
     */
    @Override
    public String getMessage() {
        return this.message;
    }

    /* (non-Javadoc)
     * @see cn.hg.jbsa.admin.dto.BaseResponseDto#isSuccess()
     */
    @Override
    public boolean isSuccess() {
        return this.success;
    }

    public BaseResponseDto<T> setCode(int code) {
        this.code = code;
        return this;
    }

    public BaseResponseDto<T> setData(T data) {
        this.data = data;
        return this;
    }

    public BaseResponseDto<T> setMessage(String message) {
        this.message = message;
        return this;
    }

    public BaseResponseDto<T> setSuccess(boolean success) {
        this.success = success;
        return this;
    }

}
